package com.example.base.demo.job;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.concurrent.TimeUnit;

/**
 * @author TangDan
 * @version 1.0
 * @since 2023/3/7
 */
public class TestTask {

    // 每两秒钟执行一次
    @Async
    @Scheduled(cron = "*/2 * * * * ?")
    public void testTask1() throws InterruptedException {
        // 任务处理逻辑
        TimeUnit.SECONDS.sleep(3);
        System.out.println(LocalDateTime.now());
        String name = Thread.currentThread().getName();
        System.out.println("TestTask1: "+name);
    }

    @Async
    // 每两秒钟执行一次
    @Scheduled(cron = "*/2 * * * * ?")
    public void testTask2() throws InterruptedException {
        // 任务处理逻辑
        System.out.println(LocalDateTime.now());
        String name = Thread.currentThread().getName();
        System.out.println("TestTask2: "+name);
    }
}
